//
//  MCLabel.m
//  FangYunERP
//
//  Created by YuHuaMac on 2017/11/23.
//  Copyright © 2017年 YuHuaMac. All rights reserved.
//

#import "MCLabel.h"

@implementation MCLabel

+ (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(CGFloat )font
{
    
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
//    label.text = title;
//    label.font = [UIFont systemFontOfSize:font];
//    label.numberOfLines = 0;
//    [label sizeToFit];
//    CGFloat height = label.frame.size.height;
//    return height;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
    label.text = title;
    label.numberOfLines = 0;
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil].size;
    return defaultSize.height;
}

+ (CGFloat)getWidthWithTitle:(NSString *)title withFontSize:(CGFloat )fontSize font:(UIFont *)font; {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreen.size.width, 0)];
    label.text = title;
    label.font = font;
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    [label sizeToFit];
    
    return defaultSize.width;
}
+ (CGFloat)getWidthWithTitle:(NSString *)title withFontSize:(CGFloat )fontSize
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreen.size.width, 0)];
    label.text = title;
//    label.font = font;
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    [label sizeToFit];
    
    return defaultSize.width;
}
+ (CGFloat)getHeightWithTitle:(NSString *)title withFontSize:(CGFloat )fontSize
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreen.size.width-18*2, 0)];
    label.text = title;
    label.numberOfLines = 0;
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(kUIScreen.size.width, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    return defaultSize.height;
}

+ (CGFloat)getMarginHeightWithTitle:(NSString *)title withFontSize:(CGFloat )fontSize
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreen.size.width-18-68, 0)];
    label.text = title;
    label.numberOfLines = 0;
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(kUIScreen.size.width, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    return defaultSize.height;
}
//+ (CGFloat)getHeightWithTitle:(NSString *)title withWidth:(NSInteger )width withFontSize:(CGFloat )fontSize
//{
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
//    label.text = title;
//    label.numberOfLines = 0;
//    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
//    CGSize defaultSize = [title boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
//    return defaultSize.height;
//}
@end
